//
//  MicroTableViewCell.m
//  TourPlay
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "MicroTableViewCell.h"
#define HEIGHT 8
#define WIDTH 8
@interface MicroTableViewCell ()

@property (nonatomic, retain) UILabel *titleL;

@property (nonatomic, retain) UIImageView *imagePhoto;
@property (nonatomic, retain) UILabel *timeL;
@property (nonatomic, retain) UILabel *addL;
@property (nonatomic, retain) UILabel *watchL;
@property (nonatomic, retain) UILabel *likeL;

@end


@implementation MicroTableViewCell

- (void)dealloc
{
    [_imagePhoto release];
    [_titleL release];
    [_timeL release];
    [_addL release];
    [_watchL release];
    [_likeL release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{

    
    UIView *viewBack = [[UIView alloc] initWithFrame:CGRectMake(WIDTH, 0, SCREEN_WIDTH - WIDTH * 2, (SCREEN_HEIGHT - 50 - 49 - 64) / 3.f - HEIGHT)];
    viewBack.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.9];
    // 圆角
    viewBack.layer.cornerRadius = 4.f;
    
    
    [self.contentView addSubview:viewBack];
    [viewBack release];
    
    
    self.imagePhoto = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, viewBack.frame.size.height / 1.35, viewBack.frame.size.height)];
    self.imagePhoto.backgroundColor = [UIColor clearColor];
    
    // 设置照片左上角和左下角为圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imagePhoto.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(2, 2)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.imagePhoto.bounds;
    maskLayer.path = maskPath.CGPath;
    self.imagePhoto.layer.mask = maskLayer;
    // 缩放模式
    self.imagePhoto.contentMode = UIViewContentModeScaleAspectFill;
    [viewBack addSubview:self.imagePhoto];
    
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(self.imagePhoto.frame.origin.x + self.imagePhoto.frame.size.width + 10, viewBack.frame.size.height * 0.08, viewBack.frame.size.width - (self.imagePhoto.frame.origin.x + self.imagePhoto.frame.size.width + 10 + 10), viewBack.frame.size.height * 0.35)];
    //    self.titleL.backgroundColor = [UIColor orangeColor];
    self.timeL.tintColor = [UIColor colorWithRed:0.14 green:0.01 blue:0 alpha:1];
    self.titleL.numberOfLines = 0;
    // 粗体设置
    self.titleL.font = [UIFont boldSystemFontOfSize:14.8f];
    [viewBack addSubview:self.titleL];
    [_titleL release];
    
    self.timeL = [[UILabel alloc] initWithFrame:CGRectMake(self.titleL.frame.origin.x, self.titleL.frame.origin.y * 1.6 + self.titleL.frame.size.height, self.titleL.frame.size.width, 17.f)];
    //    self.timeL.backgroundColor = [UIColor orangeColor];
    self.timeL.font = [UIFont systemFontOfSize:14.f];
    // 粗体设置
    //    self.timeL.font = [UIFont systemFontOfSize:12.8f];
    self.timeL.textColor = [UIColor colorWithRed:0.74 green:0.72 blue:0.73 alpha:1];
    [viewBack addSubview:self.timeL];
    [_timeL release];
    
    self.addL = [[UILabel alloc] initWithFrame:CGRectMake(self.timeL.frame.origin.x, self.timeL.frame.origin.y + self.timeL.frame.size.height + 3, self.timeL.frame.size.width, self.timeL.frame.size.height)];
    self.addL.font = self.timeL.font;
    self.addL.textColor = self.timeL.textColor;
    [viewBack addSubview:self.addL];
    [_addL release];
    
    UIImageView *likeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(viewBack.frame.size.width - 21 - 25, (viewBack.frame.size.height - 16 - 8), 21, 16)];
    likeImageV.image = [UIImage imageNamed:@"Indexnew_love@2x.png"];
    [viewBack addSubview:likeImageV];
    [likeImageV release];
    
    self.likeL = [[UILabel alloc] initWithFrame:CGRectMake(likeImageV.frame.origin.x + likeImageV.frame.size.width, likeImageV.frame.origin.y - 1, viewBack.frame.size.width - (likeImageV.frame.origin.x + likeImageV.frame.size.width) - 3, 18)];
    //    self.likeL.backgroundColor = [UIColor orangeColor];
    self.likeL.adjustsFontSizeToFitWidth = YES;
    self.likeL.textAlignment = NSTextAlignmentCenter;
    self.likeL.textColor = self.timeL.textColor;
    self.likeL.font = [UIFont systemFontOfSize:13.5f];
    [viewBack addSubview:self.likeL];
    [_likeL release];
    
    UIImageView *watchImageV = [[UIImageView alloc] initWithFrame:CGRectMake(likeImageV.frame.origin.x - likeImageV.frame.size.width - 50, likeImageV.frame.origin.y, likeImageV.frame.size.width, likeImageV.frame.size.height)];
    watchImageV.image = [UIImage imageNamed:@"Indexnew_eye@2x.png"];
    [viewBack addSubview:watchImageV];
    [watchImageV release];
    
    self.watchL = [[UILabel alloc] initWithFrame:CGRectMake(watchImageV.frame.origin.x + watchImageV.frame.size.width, self.likeL.frame.origin.y, likeImageV.frame.origin.x - (watchImageV.frame.origin.x + watchImageV.frame.size.width) - 10, self.likeL.frame.size.height)];
    //    self.watchL.backgroundColor = [UIColor orangeColor];
    self.watchL.adjustsFontSizeToFitWidth = YES;
    self.watchL.textAlignment = self.likeL.textAlignment;
    self.watchL.textColor = self.likeL.textColor;
    self.watchL.font = self.likeL.font;
    [viewBack addSubview:self.watchL];
    [_watchL release];
    
    
    // 夜间模式
    [self addColorChangedBlock:^{
        viewBack.nightBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        viewBack.normalBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        
        self.titleL.nightTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        self.titleL.normalTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        
    }];
}

- (void)setContentMod:(ContentMod *)contentMod
{
    if (_contentMod != contentMod) {
        [_contentMod release];
        _contentMod = [contentMod retain];
    }
 
    
    NSURL *url = [NSURL URLWithString:self.contentMod.pic];
    [self.imagePhoto sd_setImageWithURL:url placeholderImage:PICHOLDEER];
    
    self.titleL.text = self.contentMod.title;
    
    self.timeL.text = [NSString stringWithFormat:@"时间:%@", self.contentMod.timestr];
    self.addL.text = [NSString stringWithFormat:@"地址:%@", self.contentMod.address];
    
    self.likeL.text = [NSString stringWithFormat:@"%ld", self.contentMod.likercount];
    self.watchL.text = [NSString stringWithFormat:@"%ld", self.contentMod.viewcount];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
